--*-----------------------------------------------------------------------------
--
-- HIKE_ALBUM
--
--*-----------------------------------------------------------------------------
IF NOT EXISTS(
  SELECT 1
    FROM information_schema.tables
   WHERE table_name = 'HIKE_ALBUM'
)
BEGIN
  CREATE TABLE HIKE_ALBUM
  (
    ID INT IDENTITY(1,1) NOT NULL
  , HIKE_ID INT NOT NULL
  , ALBUM_ID INT NOT NULL
  )
  ALTER TABLE HIKE_ALBUM ADD CONSTRAINT PK_HIKE_ALBUM PRIMARY KEY(ID) 
  ALTER TABLE HIKE_ALBUM ADD CONSTRAINT FK_HIKE_ALBUM_HIKE FOREIGN KEY(HIKE_ID) REFERENCES HIKE(ID) 
  ALTER TABLE HIKE_ALBUM ADD CONSTRAINT FK_HIKE_ALBUM_ALBUM FOREIGN KEY(ALBUM_ID) REFERENCES ALBUM(ID)
  CREATE UNIQUE INDEX UQ_HIKE_ALBUM ON HIKE_ALBUM(HIKE_ID, ALBUM_ID)
  CREATE INDEX IX_HIKE_ALBUM_HIKE ON HIKE_ALBUM(HIKE_ID)
  CREATE INDEX IX_HIKE_ALBUM_ALBUM ON HIKE_ALBUM(ALBUM_ID)
END
GO
